home *** CD-ROM | disk | FTP | other *** search
- //--------------------------------------------------------------------------------------------
- // Initialization Code
- //
- // by Philip McBride
- // parts taken from Apple DTS sample code
- //
- //--------------------------------------------------------------------------------------------
-
-
- #include <AppleEvents.h>
- #include <ToolUtils.h>
- #include <Resources.h>
- #include <menus.h>
- #include <PictUtil.h>
- #include <QDOffScreen.h>
- #include <Errors.h>
- #include "GameControls.h"
- #include "extern.h"
- #include "inits.h"
-
- //--------------------------------------------------------------------------------------------
- // Initialize the Toolbox
- //
- void InitializeToolbox(void)
- {
- short index ;
- long gestaltResponse;
- short numMoreMasters = 20;
- Handle menuBar = nil;
-
- InitGraf(&qd.thePort);
- InitFonts();
- InitWindows();
- InitMenus();
- TEInit();
- InitDialogs(0L);
- InitCursor();
- MaxApplZone();
-
- SetZone(ApplicZone());
- for( index = 1; index <= numMoreMasters; index++) MoreMasters();
-
- FlushEvents(everyEvent, 0);
-
- // Check for Drag and Drop
- if ((Gestalt(gestaltDragMgrAttr, &gestaltResponse) != noErr) ||
- (!(gestaltResponse & (1 << gestaltDragMgrPresent))))
- {
- StopAlert(kMyStopAlertID, 0L);
- ExitToShell();
- }
-
- // Check for QuickDraw 3D
- if ((Gestalt(gestaltQD3D, &gestaltResponse) != noErr) ||
- gestaltResponse == gestaltQD3DNotPresent)
- {
- StopAlert(kMyStopAlertID, 0L);
- ExitToShell();
- }
-
- // initialize menu stuff
-
- menuBar = GetNewMBar(kMyMenuBar); // Read menus into menu bar
-
- if ( menuBar == nil )
- ExitToShell(); // if we dont have it then quit - your app
- // needs a dialog here
-
- SetMenuBar(menuBar); // Install menus
- DisposHandle(menuBar);
-
- AddResMenu(GetMHandle(mApple), 'DRVR'); // Add DA names to Apple menu
-
- MyAdjustMenus() ;
- DrawMenuBar();
- }
-
- //--------------------------------------------------------------------------------------------
- // Initialize Globals
- //
- void InitializeGlobals(void)
- {
- gQuit = gQuitting = false;
-
- Q3Initialize();
- }
-
- //--------------------------------------------------------------------------------------------
- // Deallocate Globals
- //
- void DeallocateGlobals(void)
- {
- Q3Exit();
- }
-
- //--------------------------------------------------------------------------------------------
- // Adjust Menus
- //
- void MyAdjustMenus( void )
- {
- WindowPtr theWindow ;
- MenuHandle theMenu ;
-
- theWindow = FrontWindow() ;
-
- if( theWindow != nil ) {
-
- theMenu = GetMHandle ( mFile ) ;
-
- EnableItem ( theMenu, iClose );
-
- }
- else {
-
- theMenu = GetMHandle ( mFile ) ;
-
- DisableItem ( theMenu, iClose );
- }
-
- DrawMenuBar() ;
- }
-
- //--------------------------------------------------------------------------------------------
- // Initialize Apple Events
- //
- void InitAEStuff( void )
- {
- OSErr err;
-
- // Set up the self-addressed descriptor record.
- pSelfPSN.highLongOfPSN = 0;
- pSelfPSN.lowLongOfPSN = kCurrentProcess; // Use this instead of GetCurrentProcess
- err = AECreateDesc(typeProcessSerialNumber,(Ptr)&pSelfPSN,
- sizeof(ProcessSerialNumber),&pSelfAddress);
-
- pnilDesc.descriptorType = typeNull; // Initialize the global nil descriptor record.
- pnilDesc.dataHandle = nil;
-
- RegisterMyEvents() ; // and finally register appleEvent handlers
- }
-
- //--------------------------------------------------------------------------------------------
- // Check if Supports Apple Events
- //
- Boolean SupportsAEVT(void)
- {
- OSErr err;
- long response;
-
- if (!myTrapAvailable(kGestaltTrap))
- return false;
-
- err = Gestalt(gestaltAppleEventsAttr,&response);
- if (err!=noErr)
- return false;
-
- return (response && (response << gestaltAppleEventsPresent));
- }
-
- //--------------------------------------------------------------------------------------------
- // Register Apple Events
- //
- void RegisterMyEvents(void)
- {
- OSErr err;
-
- if (!SupportsAEVT())
- return;
-
- err = AEInstallEventHandler(kCoreEventClass,kAEOpenApplication,NewAEEventHandlerProc(MyAEHandleOAPP),0L,false);
- if (err!=noErr)
- return;
-
- err = AEInstallEventHandler(kCoreEventClass,kAEOpenDocuments,NewAEEventHandlerProc(MyAEHandleODOC),0L,false);
- if (err!=noErr)
- return;
-
- err = AEInstallEventHandler(kCoreEventClass,kAEPrintDocuments,NewAEEventHandlerProc(MyAEHandlePDOC),0L,false);
- if (err!=noErr)
- return;
-
- err = AEInstallEventHandler(kCoreEventClass,kAEQuitApplication,NewAEEventHandlerProc(MyAEHandleQUIT),0L,false);
- if (err!=noErr)
- return;
- }
-